package leetcode.code1405;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	int len;

	public String longestDiverseString(int a, int b, int c) {
		int[] cs = new int[] { a, b, c };
		len = a + b + c;
		StringBuffer ans = new StringBuffer();
		this.f(cs, -1, 0, ans, 0);
		return new String(ans);
	}

	private void f(int[] cs, int last, int count, StringBuffer ans, int p) {
		if (p == len) {
			return;
		}
		int max = 0;
		int select = -1;
		for (int i = 0; i < 3; i++) {
			if (count == 2 && i == last) {
				continue;
			}
			if (cs[i] > max) {
				max = cs[i];
				select = i;
			}
		}
		if (select == -1) {
			return;
		}
		ans.append((char) (select + 'a'));
		cs[select]--;
		this.f(cs, select, select == last ? 2 : 1, ans, p + 1);
	}

	@Override
	public void debug1() {
		HelpDebug.compare("ccaccbcc", this.longestDiverseString(1, 1, 7));

	}

	@Override
	public void debug2() {
		HelpDebug.compare("aabaa", this.longestDiverseString(7, 1, 0));
	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub
		HelpDebug.compare("aabbc", this.longestDiverseString(2, 2, 1));

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
//		so.debug1();
//		so.debug2();
		so.debug3();
		so.debug4();

	}

}
